package com.xd.clap.controller;

import com.xd.clap.entity.Admin;
import com.xd.clap.entity.request.LoginParam;
import com.xd.clap.entity.request.PageParam;
import com.xd.clap.entity.request.WxParam;
import com.xd.clap.entity.response.Result;
import com.xd.clap.services.AdminService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService as;

    /**
     * 小程序用户登录
     */
    @PostMapping("/login")
    public Result login(@RequestBody LoginParam loginParam) {
        return as.adminLogin(loginParam);
    }

    /**
     * 获取openid
     * @param wxParam
     * @return
     */
    @PostMapping("/wxLogin")
    public Result wxLogin(@RequestBody WxParam wxParam) {
        return as.wxLogin(wxParam);
    }

    /**
     * 网页管理员登录
     */
    @PostMapping("/loginByPwd")
    public Result loginByPwd(@RequestBody LoginParam loginParam) {
        return as.adminLoginByPwd(loginParam);
    }

    /**
     * 获取管理员分页列表
     */
    @PostMapping("/getAdminPage")
    public Result getAdminPage(@RequestBody PageParam pageParam) {
        return as.getAdminPage(pageParam);
    }

    /**
     * 删除管理员
     */
    @DeleteMapping("/delAdmin")
    public Result delAdmin( Admin admin) {
        return as.delAdmin(admin.getId());
    }

    /**
     * 更新或者插入管理员
     */
    @PutMapping("/updateAdmin")
    public Result updateAdmin(@RequestBody Admin admin) {
        return as.updateAdmin(admin);
    }


    /**
     * 发送验证码
     * @return
     */
    @GetMapping("/loginSendSms")
    public Result loginSendSms(@RequestParam String phone) {
        return as.loginSendSms(phone);
    }
    /**
     *app登录
     * @param loginParam
     * @return
     */
    @PostMapping("/appLogin")
    public Result appLogin(@RequestBody LoginParam loginParam) {
        return as.appLogin(loginParam);
    }

}
